package com.tgjs.sphoto.activity;

import android.app.DialogFragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;

import com.blankj.utilcode.util.SPUtils;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.github.chrisbanes.photoview.PhotoView;
import com.tgjs.sphoto.constant.ConstantValues;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * Created by dql on 2018/8/21.
 */

public class PhotoDialog extends DialogFragment {
    @BindView(R.id.photoView)
    PhotoView mPhotoView;
    Unbinder unbinder;
    private PhotoDetailActivity activity;
    private Window mWindow;


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.dialog_photo, container);
        getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
//		setStyle(STYLE_NO_FRAME, android.R.style.Theme_Holo_Light);
        Window window = getDialog().getWindow();
        window.setGravity(Gravity.CENTER); //可设置dialog的位置
        window.getDecorView().setPadding(0, 0, 0, 0); //消除边距

        WindowManager.LayoutParams lp = window.getAttributes();
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;   //设置宽度充满屏幕
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        window.setAttributes(lp);
        Log.e("url", SPUtils.getInstance().getString(ConstantValues.THUMB_URL));
        unbinder = ButterKnife.bind(this, view);
        Glide.with(getActivity()).load(SPUtils.getInstance().getString(ConstantValues.THUMB_URL)).diskCacheStrategy(DiskCacheStrategy.ALL).dontAnimate().into(mPhotoView);

        return view;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @OnClick(R.id.photoView)
    public void onViewClicked() {
        dismiss();
    }
}
